﻿using Avalonia;
using Avalonia.Media;
using Bread.Utility;
using SkiaSharp;

namespace Bread.Mvc.Avalonia;

public static class PrimitiveHelper
{
    public static Color ToAvalonia(this SKColor color)
    {
        return new Color(color.Alpha, color.Red, color.Green, color.Blue);
    }

    public static SKColor ToSKColor(this Color color)
    {
        return new SKColor(color.R, color.G, color.B, color.A);
    }

    public static Rect WithXY(this Rect rc, double x, double y)
    {
        return new Rect(x, y, rc.Width, rc.Height);
    }

    public static Rect WithWH(this Rect rc, double w, double h)
    {
        return new Rect(rc.X, rc.Y, w, h);
    }

    public static Point ToPoint(this PointD p)
    {
        return new Point(p.X, p.Y);
    }

    public static PointD ToPointD(this Point p)
    {
        return new PointD(p.X, p.Y);
    }

    public static Rect ToRect(this RectD rc)
    {
        return new Rect(rc.X, rc.Y, rc.Width, rc.Height);
    }

    public static RectD ToRect(this Rect rc)
    {
        return new RectD(rc.X, rc.Y, rc.Width, rc.Height);
    }

    public static bool IsInside(this Point p, double x, double y, double w, double h)
    {
        return (p.X >= x) && (p.X <= x + w) && (p.Y >= y) && (p.Y <= y + h);
    }
}
